import axios from 'axios'
import { defineStore } from 'pinia'
import { NewList } from '../../types/data'
export default defineStore('newslist', {
  state(){
  return {
      list: [] as NewList
    }
  },
  actions: {
    // curId：要显示的新闻列表对应的频道的id
    async getNewsList(curId: number){
      const url = 'http://geek.itheima.net/v1_0/articles?channel_id='+curId+'&timestamp=1657361711251'
      // const res = await axios.get<后端返回的数据类型>(url)
      const res = await axios.get<{data:{pre_timestamp: string, results: NewList}, message: string}>(url)
      // console.log(res.data.data.results)
      this.list = res.data.data.results
    }
  }
})